<template>
  <div style="align-content: center">
    <el-link style="height: 20px" target="_blank" v-text="discussTitle"></el-link>
    <div>
      <el-table
        :data="discussMsgList"
        border
        style="width: 100%">
        <el-table-column prop="msgContent">
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-form ref="form" label-width="80px">
        <el-form-item label="">
          <el-input v-model="msgContent"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">发送</el-button>
          <el-button @click="close">关闭</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>

<script>
export default {
  name: 'Discuss',
  data () {
    return {
      discussId: this.$route.query.id,
      discussTitle: '',
      form: '',
      discussMsgList: [],
      msgContent: ''
    }
  },
  mounted () {
    this.initHandle()
  },
  methods: {
    initHandle () {
      this.getDiscussDetail()
      this.getDiscussMsgList()
    },
    getDiscussMsgList () {
      let data = {
        'discussId': this.discussId
      }
      this.$axios({
        method: 'post',
        url: `/discussMsg/list`,
        data: this.$qs.stringify(data)
      }).then(res => {
        let list = []
        res.data.data.forEach(x => {
          let obj = {}
          Object.assign(obj, {'msgContent': x.msgContent})
          Object.assign(obj, {'msgId': x.msgId})
          Object.assign(obj, {'manId': x.manId})
          Object.assign(obj, {'msgType': x.msgType})
          Object.assign(obj, {'status': x.status})
          list.push(obj)
        })
        this.discussMsgList = list
      })
    },
    getDiscussDetail () {
      let data = {
        'discussId': this.discussId
      }
      this.$axios({
        method: 'post',
        url: `/discuss/detail`,
        data: this.$qs.stringify(data)
      }).then(res => {
        if (res.data.errorCode !== 0) {
          this.$message.error(res.data.errorMsg)
        } else {
          this.discussTitle = res.data.data.discussTitle
        }
      })
    },
    onSubmit () {
      let data = {
        'discussId': this.discussId,
        'userId': 'caeca614906f4b3a9e6cfd352f016e86',
        'msgContent': this.msgContent
      }
      this.$axios({
        method: 'post',
        url: `/discussMsg/add`,
        data: this.$qs.stringify(data)
      }).then(res => {
        if (res.data.errorCode !== 0) {
          this.$message.error(res.data.errorMsg)
        } else {
          this.msgContent = ''
          this.$message.success(res.data.errorMsg)
          this.getDiscussMsgList()
        }
      })
    },
    close () {
      console.log('close!')
    }
  }
}
</script>

<style scoped>

</style>
